<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	$return['ischecklogin']=model('core/core')->checklogin('','',true);
	$_SESSION['memberid']=$this->model('member')->checkmember();
	$_SESSION['logout_forward']='jy_aihire/home';
	$item=pdo_get('jy_aihire_member',array('id'=>$_SESSION['memberid'],'uniacid'=>$_SESSION['uniacid']));
	if(!$item){
		exi('找不到会员信息！','error');
	}
	$item['avatar']=tomedia($item['avatar']);
	if($item['pcd']){
		$item['pcd']=json_decode($item['pcd'],true);
	}else{
	   $item['pcd']=array('province'=>''); 
	}
	$item['oldmobile']=$item['mobile'];
	$return['item']=$return['post']=$item;
	$return['years']=array();
	for($i=1950;$i<2100;$i++){
		$return['years'][]=$i;
	}
	$return['months']=array(1,2,3,4,5,6,7,8,9,10,11,12);
	$return['days']=array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31);
	$return['xueli']=$this->xueli_type;
	set_html('title','设置');
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if($postdata['login_type']>0 && $postdata['oldmobile']!=$postdata['mobile'] && !check_sms_code($postdata['smscode'])){
		$oldmobile=pdo_getcolumn('jy_aihire_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['memberid']),'mobile');
		if($postdata['mobile']!=$oldmobile){
			exi('手机验证码错误！不能修改手机！','error');
		}
	}elseif($postdata['login_type']>0 && $postdata['oldmobile']!=$postdata['mobile']){
		$realmobile=true;
		$postdata['realmobile']=$postdata['mobile'];
	}
	if(strlen($postdata['mobile'])!=11 || $postdata['mobile'][0]!='1' || !is_numeric($postdata['mobile'])){
		exi('手机号码格式错误，请输入11位，1开头的手机号！！','error');
	}
	$uid=pdo_getcolumn('jy_aihire_member',array('mobile'=>trim($postdata['mobile']),'uniacid'=>$_SESSION['uniacid'],'id <>'=>$_SESSION['memberid']),'id');
	if($uid && $postdata['mobile']!=$postdata['oldmobile']){
		//exi('手机号已存在，请更换!','error');
	}
	if(!$postdata['nickname']){
		exi('请先完善会员昵称！','error');
	}
	if(!$postdata['sex']){
		exi('请先完善性别！','error');
	}
	if(!$postdata['birth']){
		exi('请先完善出生日期！','error');
	}
	$postdata['pcd']=$postdata['pcd']?ijson_encode($postdata['pcd']):'{"广东","深圳","龙华"}';
	$fields=array('birth','nickname','qq','pcd','mobile','xueli','sex');
	$data=array_fields($fields,$postdata);
	pdo_update('jy_aihire_member',$data,array('id'=>$_SESSION['memberid'],'uniacid'=>$_SESSION['uniacid']));
	$_SESSION['member']['nickname']=$postdata['nickname'];
	exi('设置成功！','','goback');
}
if($_RQ['op']=='getdata'){
	$register=uni_setting('register');
	$register['login_type']=$register['login_type']?:0;
	$register['user_xieyi']=$register['user_xieyi']?:'本平台尊重和保护用户的隐私。本隐私政策将告诉您我们如何收集和使用有关您的信息，以及我们如何保护这些信息的安全。您成为本平台用户前务必仔细阅读本隐私条款并同意所有隐私条款。本隐私政策条款在您注册成为本平台用户后立即生效，并对您及本平台产生约束力。';
	$return['register']=$register;
	exi($return);
}
if($_RQ['op']=='postmobile'){
	$postdata=get_postdata();
	if($postdata['check']!=1){
			exi('请先阅读协议！','error');
	}
	if($postdata['login_type']>0 && !check_sms_code($postdata['sms_code'])){
			exi('手机验证码错误！','error');
	}
	if(strlen($postdata['mobile'])!=11 || $postdata['mobile'][0]!='1' || !is_numeric($postdata['mobile'])){
			exi('手机号码格式错误，请输入11位，1开头的手机号！！','error');
	}
	$check=pdo_get('jy_aihire_member',array('mobile'=>$postdata['mobile'],'id <>'=>$_SESSION['memberid'],'uniacid'=>$_SESSION['uniacid']));
	if($check['id']){
		//exi('该手机号已经存在，已绑定别的账户！！','error');
	}
	if($postdata['login_type']>0){
		$realmobile=true;
		$postdata['realmobile']=$postdata['mobile'];
	}
	$fields=array('mobile');
	$data=array_fields($fields,$postdata);
	$_SESSION['member']['mobile']=$postdata['mobile'];
	pdo_update('jy_aihire_member',$data,array('id'=>$_SESSION['memberid'],'uniacid'=>$_SESSION['uniacid']));
	exi('设置成功！');
}